﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace uTrade.Resources
{
    public class ListViewItemStyleSelector : StyleSelector
    {
        public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject container)
        {
            Style st = new Style();
            st.TargetType = typeof(ListViewItem);
            Setter backgroundSetter = new Setter();
            backgroundSetter.Property = ListViewItem.BackgroundProperty;
            ListView listView = ItemsControl.ItemsControlFromItemContainer(container) as ListView;
            int index = listView.ItemContainerGenerator.IndexFromContainer(container);
            if (index % 2 == 0)
                backgroundSetter.Value = Brushes.LightBlue;
            else
            {
                backgroundSetter.Value = Brushes.Beige;
            }
            st.Setters.Add(backgroundSetter);
            return st;
        }
    }
}